<?php
namespace Admin\Controller;

/**
 * 前台首页控制器
 */
class ClientController extends AdminController {

	
    public function index(){
        /* 查询条件初始化 */
        $map = array();
        $map  = array('delflag' => 0);
        $nickname = I('nickname');
        if($nickname){
            $map['nickname'] = array('like', '%'.$nickname.'%');
        }
        $isDistributor = I('status');
        if($isDistributor){
            $map['isDistributor'] = $isDistributor;
        }
        $list = $this->lists('client', $map,'createAt,id');
        // 记录当前列表页的cookie
        Cookie('__forward__',$_SERVER['REQUEST_URI']);

        // $this->assign('list',C('CONFIG_GROUP_LIST'));
        // $this->assign('group_id',I('get.group',0));
        $this->assign('list', $list);
        $this->assign('isDistributor', $isDistributor);
        $this->assign('nickname', $nickname);
        $this->meta_title = '客户';
        $this->display();
    }

    public function xiaxian(){
        $id = I('id');
        $nickname = I('nickname');
        $map = array('parentDistributor' => $id, 'delflag' => 0 );
        if($nickname){
            $map['nickname'] = array('like', '%'.$nickname.'%');
        }
        $m = M('Client');
        $list = $this->lists('client', $map,'createAt,id');
        $client = $m->where(array('id' => $id))->find();
        // if($r){
        //     $this->success('操作成功');
        // }else{
        //     $this->error('操作失败');
        // }
        $this->assign('client', $client);
        $this->assign('list', $list);
        $this->display();
    }

    public function setDis(){
        $ids = I('ids');
        $m = M('Client');
        $r = $m->where(array('id' => array('in', $ids)))->save(array('isDistributor' => 1));
        if($r){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }

}
?>